package com.zb.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zb.entity.ZjFactorySet;
import com.zb.mapper.ZjFactorySetMapper;
import com.zb.service.ZjFactorySetService;
import com.zb.vo.FactorySetVo;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 厂商设置表 服务实现类
 * </p>
 *
 * @author WEN
 * @since 2024-02-27
 */
@Service
public class ZjFactorySetServiceImpl extends ServiceImpl<ZjFactorySetMapper, ZjFactorySet> implements ZjFactorySetService {

    // 初始化或重置厂商设置
    @Override
    public void initOrRestoreDefaultFactorySet(Long custAccId) {
        ZjFactorySet factorySet = new ZjFactorySet();
        factorySet.setId(custAccId);
        factorySet.setFactoryCheckStrategy(1);
        this.saveOrUpdate(factorySet);
    }

    // 获取品牌厂商全局设置
    @Override
    public FactorySetVo getFactorySet(Long custAccId) {
        ZjFactorySet factorySet = this.getById(custAccId);
        FactorySetVo vo = new FactorySetVo();
        if (null == factorySet) {
            vo.setFactoryCheckStrategy(1);
            return vo;
        }
        BeanUtil.copyProperties(factorySet, vo);
        return vo;
    }

    // 保存厂商设置
    @Override
    public void saveFactorySet(Long custAccId, FactorySetVo factorySetVo) {
        ZjFactorySet set = this.getById(custAccId);
        if (null != set) {
            ZjFactorySet factorySet = new ZjFactorySet();
            BeanUtil.copyProperties(factorySetVo, factorySet);
            factorySet.setId(custAccId);
            this.updateById(factorySet);
            return;
        }
        set = new ZjFactorySet();
        BeanUtil.copyProperties(factorySetVo, set);
        set.setId(custAccId);
        this.save(set);
    }
}
